package cn.virens.web.components.open.wxmp.session;

import org.springframework.stereotype.Component;

import cn.virens.web.components.open.session.WxSession;

/**
 * 微信Session管理器
 * 
 * @author virens
 */
@Component
public class WxMpSessionManagerImpl extends WxMpSessionManagerBySpring {

	@Override
	public WxSession getSession(String openid) {
		return getSession(openid, true);
	}

	@Override
	public WxSession getSession(String openid, boolean create) {
		try {
			WxSession saved = getSessionByCache(openid);

			if (saved != null && !saved.isExpired()) {
				return createSession(openid, saved);
			} else if (create) {
				return createSession(openid);
			} else {
				return null;
			}
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public void putSession(String openid, WxSession session) {
		this.putSessionByCache(openid, session);
	}
}
